#include <54func.h>
typedef struct node_s {
    int data;
    struct node_s * pNext;
} node_t;
typedef struct list_s {
    node_t *pHead;
    node_t *pTail;
} list_t;
void headInsert(node_t ** ppHead, node_t ** ppTail, int data){
    node_t *pNew = (node_t *)malloc(sizeof(node_t));
    memset(pNew,0,sizeof(node_t)); // pNew的指针域置为NULL
    pNew->data = data;
    if(*ppHead == NULL){
        *ppHead = pNew;
        *ppTail = pNew;
    }
    else{
        pNew->pNext = *ppHead;
        *ppHead = pNew;
    }
}
void tailInsert(node_t **ppHead,node_t **ppTail,int data){
    node_t * pNew = (node_t *)calloc(1,sizeof(node_t));
    pNew->data = data;
    if(*ppHead == NULL){
        *ppHead = pNew;
        *ppTail = pNew;
    }
    else{
        (*ppTail)->pNext = pNew;
        *ppTail = pNew;
    }
}
void visitList(node_t *pHead){
    node_t * pCur = pHead;
    while(pCur){
        printf("%d ", pCur->data);
        pCur = pCur->pNext;
    }
    printf("\n");
}
//int main(int argc, char *argv[])
//{
//    node_t * pHead = NULL;
//    node_t * pTail = NULL;
//    for(int i = 0; i < 10; ++i){
//        //headInsert(&pHead,&pTail,i);
//        tailInsert(&pHead,&pTail,i);
//        visitList(pHead);
//    }
//    return 0;
//}
void *threadFunc(void *arg){
    list_t *pList = (list_t *)arg;
    printf("I am child!\n");
    visitList(pList->pHead);
    return NULL;
}
int main(){
    list_t list;
    list.pHead = NULL;
    list.pTail = NULL;
    for(int i = 0; i < 9; ++i){
        tailInsert(&list.pHead,&list.pTail,i);
    }
    pthread_t tid;
    pthread_create(&tid,NULL,threadFunc,&list); // list_t *
    sleep(1);
    return 0;
}

